<!-- 职级编辑弹窗 -->
<template>
    <el-dialog
      :title="isUpdate?'查看任务运行日志':'查看任务运行日志'"
      :visible="visible"
      width="80%"
      :destroy-on-close="true"
      :lock-scroll="false"
      @open="loaddata"
      @update:visible="updateVisible">

      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        height="calc(100vh - 415px)">
        <template slot="billNo" slot-scope="{row}">
          <div style="white-space:pre-wrap">{{ row.billNo }}</div>
        </template>
        <!-- 表头工具栏 -->
        <template slot="toolbar" v-if="false">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            >NC回写
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="false"
            >删除
          </el-button>
        </template>
      </ele-pro-table>

      <div slot="footer">
        <el-button @click="updateVisible(false)">关闭</el-button>
        <el-button v-if="false"
          type="primary"
          @click="save"
          >保存
        </el-button>
      </div>
    </el-dialog>
  </template>

  <script>
  export default {
    name: 'TaskLog',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data: Object
    },
    data() {
      return {
        // 表单数据
        //form: Object.assign({status: 1}, this.dataItem),
        url: '/nctasklog/index',
      // 表格列配置
      columns: [
        {
            prop: 'taskType',
            label: '任务名称',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'billNo',
            label: '单据号',
            showOverflowTooltip: true,
            minWidth: 440,
            align: 'center',
            slot:'billNo'
          },
          {
            prop: 'billCount',
            label: '单据数',
            showOverflowTooltip: true,
            minWidth: 80,
            align: 'center'
          },
          {
            prop: 'startTime',
            label: '开始时间',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'endTime',
            label: '结束时间',
            showOverflowTooltip: true,
            minWidth: 100,
            align: 'center'
          },
      ],
      // 表格搜索条件
      where: {taskType:this.dataItem?this.dataItem.chukNo:''},

        // 表单验证规则
        rules: {
          name: [
            {required: true, message: '请输入职级名称', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '请选择职级状态', trigger: 'blur'}
          ],
          sort: [
            {required: true, message: '请输入排序号', trigger: 'blur'}
          ]
        },
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false
      };
    },
    watch: {
      data() {
        if (this.data) {
          this.form = Object.assign({}, this.data);
          this.isUpdate = true;
        } else {
          this.form = {};
          this.isUpdate = false;
        }
      }
    },
    methods: {
      loaddata(){
        this.where.taskType="";
        if (this.data) {
          let classpath = this.data.classpath;
          if(classpath.includes("CGRK"))
          {
            this.where.taskType = "采购入库";
          }
          if(classpath.includes("GJTC"))
          {
            this.where.taskType = "购进退出";
          }
          if(classpath.includes("XSCK"))
          {
            this.where.taskType = "销售出库";
          }
          if(classpath.includes("XSTH"))
          {
            this.where.taskType = "销售退回";
          }
          if(classpath.includes("KdlMaterial"))
          {
            this.where.taskType = "物料主数据";
          }
          if(classpath.includes("KdlCustomer"))
          {
            this.where.taskType = "客户主数据";
          }
          if(classpath.includes("KdlSupplier"))
          {
            this.where.taskType = "供应商主数据";
          }
          if(classpath.includes("KdlPurchase2NC"))
          {
            this.where.taskType = "入库质检回传NC";
          }
          if(classpath.includes("QffAttach"))
          {
            this.where.taskType = "下载异常反馈附件";
          }
          if(classpath.includes("SaleReturn2NC"))
          {
            this.where.taskType = "康德乐销退同步及下发NC";
          }
          if(classpath.includes("PurchaseReturn2NC"))
          {
            this.where.taskType = "采退回传NC";
          }
          if(classpath.includes("SaleOut2NC"))
          {
            this.where.taskType = "销售出库回传NC";
          }
          if(classpath.includes("KdlGM"))
          {
            this.where.taskType = "移库回传NC";
          }
          if(classpath.includes("KdlMara"))
          {
            this.where.taskType = "主数据审批回传";
          }
          if(classpath.includes("KdlPOD"))
          {
            this.where.taskType = "同步签收记录";
          }
          if(classpath.includes("KdlRGR"))
          {
            this.where.taskType = "同步拒收订单";
          }
          if(classpath.includes("TransReport"))
          {
            this.where.taskType = "同步运输报表";
          }
          if(classpath.includes("QffAttach"))
          {
            this.where.taskType = "下载异常反馈附件";
          }
          if(classpath.includes("KdlInventory"))
          {
            this.where.taskType = "康德乐库存回传";
          }
          if(classpath.includes("KdlPurchasewe"))
          {
            this.where.taskType = "同步采购收货";
          }
          if(classpath.includes("Gsp"))
          {
            this.where.taskType = "Report";
          }

        }
        this.$refs.table.reload();
      },
      /* 保存编辑 */
      save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.loading = true;
            this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/level/edit' : '/level/add', this.form).then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit('done');
              } else {
                this.$message.error(res.data.msg);
              }
            }).catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
          } else {
            return false;
          }
        });
      },
      /* 更新visible */
      updateVisible(value) {
        this.$emit('update:visible', value);
      }
    }
  }
  </script>

  <style scoped>
  </style>
